package cn.edu.fzu.delivery.domain.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import cn.edu.fzu.delivery.domain.enums.UrgencyEnum;

public class UrgencyEnumHandler extends BaseTypeHandler<UrgencyEnum> {

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, UrgencyEnum parameter, JdbcType jdbcType)
            throws SQLException {
        ps.setInt(i, parameter.getValue());
    }


    @Override
    public UrgencyEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return UrgencyEnum.parse(rs.getInt(columnName));
    }


    @Override
    public UrgencyEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return UrgencyEnum.parse(rs.getInt(columnIndex));
    }


    @Override
    public UrgencyEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return UrgencyEnum.parse(cs.getInt(columnIndex));
    }

}
